<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>基础数据列表</title>
    <jsp:include page="../../../head.jsp"/>
</head>
<%
    String parentid = request.getParameter("parentId");
    String id = request.getParameter("id");
    if (StringUtils.isEmpty(parentid)) {
        parentid = "";
    }
    if (StringUtils.isEmpty(id)) {
        id = "";
    }
%>
<script type="text/javascript">
    var pid = "<%=parentid%>";
    var id = "<%=id%>";
    var t = "新增";
    var state_option = [["启用", "0"], ["禁用", "1"]];
    if (id) {
        t = "修改";
    }
    var gridTitle = "";
    if (pid) {
        gridTitle = t + "基础数据";
    } else {
        gridTitle = t + "基础数据类型";
    }
    var formSetting = {
        title: gridTitle,
        module: 'save',
        columns: [{
            name: "chn",
            label: "中文名",
            validate: 'validate[required]'
        }, {
            name: "en",
            label: "英文名"
        }, {
            name: "identifier",
            label: "标识符"
        }, {
            name: "use_state",
            value: "0",
            label: "使用状态",
            type: "dropdown",
            data: state_option,
            dropdownValue: "启用"
        }, {
            name: "mark",
            label: "备注",
            type: "textarea"
        }, {
            name: "id",
            label: "id",
            hidden: true
        }, {
            name: "updateUser",
            label: "备注",
            hidden: true
        }, {
            name: "parentId",
            hidden: true,
            value: pid
        }],
        form: {
            'url': 'sysval-save',
            'data': function () {
                <%--var id = "${systemValue.id}";--%>
                var id = "<%=id%>";
//                alert(id);
                if (id) {
                    var dataValue = "";
                    $.ajax({
                               url: "sysval-getData?id=" + id,
                               async: false,
                               success: function (data) {
                                   $.each(state_option, function (i, n) {
                                       if (data.systemValue.use_state == n[1]) {
                                           var dropdownName = $.mrdForm.getDropDwonLabelName(
                                                   "use_state");
                                           data[dropdownName] = n[0];
                                       }
                                   });
                                   dataValue = data;
                               }
                           });
                    return dataValue;
                } else {
                    return null;
                }
            },
            'afterAjaxSuccess': function (responseText, statusText, xhr, $form) {
                var msg = $.parseJSON(responseText.msg);
                if (msg.state == "1") {
                    if (pid) {
                        var url = "sysval-manage";
                        url += "?parentId=" + pid;
                        location.href = url;
                    } else {
                        $('#west', window.parent.document)[0].contentWindow.refresh();
                        location.reload();
                    }
                }
            }
        },
        buttons: {}
    };
    $(document).ready(function () {
        $("#formtable").mrdForm(formSetting);
    });
</script>
<body>
<div style="width: 100%">
    <div id="formtable"></div>
</div>
</body>
</html>
